﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Infrastructure.Common;
using Xiaov.SmartWeb.Model.ActiveRecord;
using AjaxPro;
using Castle.ActiveRecord;
using Xiaov.SmartWeb.Model;

namespace Xiaov.SmartWeb.Application.ZNPT
{
    public partial class WordTemplate : BasePage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(WordTemplate));
      //PM_FilterByProperty(ModulePropoty.MODULEURL, Request.Url.AbsolutePath);  
      //PM_Filter();
    }

    [AjaxPro.AjaxMethod]
    public void SaveTemplate(string FilePath)
    {
    
    }

    [AjaxPro.AjaxMethod]
    public string RolesString(object o)
    {
      return "";
    }

    [AjaxPro.AjaxMethod]
    public bool SaveUser(object userid, object username, object loginname, object password, object disable, object superadmin, object sortby, object roles, object dwbm)
    {
      try
      {
        Xiaov.SmartWeb.Model.ActiveRecord.S_PM_USER model = new S_PM_USER();
        if (!string.IsNullOrEmpty(userid.ToString()))
          model = Model.ActiveRecord.S_PM_USER.Find(userid);
        if (model == null || string.IsNullOrEmpty(model.USERID))
        {
          //如果是新增 用户密码要加密 创建一个USERID
          model.USERID = Guid.NewGuid().ToString();
          model.PASSWORD = password.ToString().Encrypt();
        }
        else
        {
          if (!string.IsNullOrEmpty(password.ToString()))
          {
            model.PASSWORD = password.ToString().Encrypt();
          }
        }
        model.USERNAME = username.ToString();
        model.LOGINNAME = loginname.ToString();
        if (disable == null)
          disable = "false";
        model.DISABLED = (disable.ToString() == "false" ? "0" : "1");
        if (superadmin == null)
          superadmin = "false";
        model.SUPERADMIN = (superadmin.ToString() == "false" ? "0" : "1");
        model.USERSORT = sortby.ToInt32();
        model.USERDEPT = dwbm.ToRequestString();
        //保存用户
        model.Save();
        model.SaveRoles(roles);
        model.RefreshCache();
        return true;
      }
      catch
      {
        return false;
      }
    }

    [AjaxPro.AjaxMethod]
    public bool DeleteUser(object userId)
    {
      try
      {
        Xiaov.SmartWeb.Model.ActiveRecord.S_PM_USER user = Model.ActiveRecord.S_PM_USER.Find(userId);
        S_PM_USERROLES.DeleteAll("USERID='" + userId + "'");
        user.Delete();
        user.RefreshCache();
        return true;
      }
      catch
      {
        return false;
      }

    }

    [AjaxPro.AjaxMethod]
    public string GetRolesDescriptByUserId(object userId)
    {
      S_PM_USER user = new S_PM_USER();
      return user.GetRolesDescriptByUserId(userId.ToString());
    }

    [AjaxPro.AjaxMethod]
    public string GetRolesIdByUserId(object userId)
    {
      S_PM_USER user = new S_PM_USER();
      return user.GetRolesIdByUserId(userId.ToString());
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
      /*  string DOCMC = t2.Text;
        string DOTMC = t3.FileName;
        string DOCZQ = t4.Text;

        if (DOCMC != "" && DOTMC != "" && DOCZQ != "")
        {
              string kzm = System.IO.Path.GetExtension(t3.FileName).ToLower();//取文件扩展名
              string time = System.DateTime.Now.ToString("yyyyMMddHHmmssffff");//("yyyy-MM-dd HH:mm:ss:fff");
              DateTime time1 = DateTime.Now;//这个time是用来传到数据库里的，因为数据库字段类型为datetime型
              string path = "upvideo/" + time + t3.FileName + kzm;//服务器文件的相对路径,并将文件名称修改为当前时间+名称
              string fullpath = MapPath(".") + "/" + path;//服务器文件的绝对路径
              t3.PostedFile.SaveAs(fullpath);//上传文件到绝对路径fullpath，同名文件覆盖，所以文件名很精确

              string sql = string.Format(@"insert into zn_docbm values('{0}','{1}','{2}','{3}')", System.Guid.NewGuid().ToString(), t2.Text, fullpath, t4.Text);

              Maticsoft.DBUtility.DbHelperOra.ExecuteSql(sql.ToString());
        }*/
    }


  }
}